#!/usr/bin/env python3
"""项目设置脚本"""

import os
import subprocess
import sys
from pathlib import Path


def create_directories():
    """创建必要的目录"""
    directories = [
        "logs",
        "data",
        "temp"
    ]
    
    for directory in directories:
        Path(directory).mkdir(exist_ok=True)
        print(f"✅ 创建目录: {directory}")


def setup_environment():
    """设置环境变量"""
    env_file = Path(".env")
    env_example = Path("env.example")
    
    if not env_file.exists() and env_example.exists():
        env_file.write_text(env_example.read_text())
        print("✅ 创建 .env 文件")
    else:
        print("ℹ️  .env 文件已存在")


def install_dependencies():
    """安装依赖"""
    print("📦 安装依赖...")
    subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
    print("✅ 依赖安装完成")


def main():
    """主函数"""
    print("🚀 设置Cairo智能合约助手项目...")
    
    create_directories()
    setup_environment()
    install_dependencies()
    
    print("\n🎉 项目设置完成！")
    print("\n📖 使用说明:")
    print("  make dev     - 启动开发环境")
    print("  make api     - 启动API服务")
    print("  make ui      - 启动UI界面")
    print("  make help    - 查看所有命令")


if __name__ == "__main__":
    main()
